echo off

rmdir .\build\ /S /Q


MSbuild "Q:\Solution File\Real Solution File\AST\AST.sln" -t:restore -p:Platform=%BUILD_CPU_MODE%
if %errorlevel% neq 0 (
echo Restore Project "AST" Fail!
exit 1
)

MSbuild "Q:\Solution File\Real Solution File\RiProgram\RiProgram.sln" -t:restore -p:Platform=%BUILD_CPU_MODE%
if %errorlevel% neq 0 (
echo Restore Project "RiProgram" Fail!
exit 1
)

MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Clean -p:Configuration=Debug;Platform=x64
if %errorlevel% neq 0 (
echo Clean Project  "AST(Debug)" Fail!
exit 1
)

MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Clean -p:Configuration=Beta;Platform=x64
if %errorlevel% neq 0 (
echo Clean Project  "AST(Beta)" Fail!
exit 1
)

MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Clean -p:Configuration=Stable;Platform=x64
if %errorlevel% neq 0 (
echo Clean Project  "AST(Stable)" Fail!
exit 1
)

MSBuild "Q:\Solution File\Real Solution File\RiProgram\RiProgram.sln" -t:Clean -p:Configuration=DebugStatic;Platform=x64
if %errorlevel% neq 0 (
echo Clean Project  "AST(DebugStatic)" Fail!
exit 1
)

MSBuild "Q:\Solution File\Real Solution File\RiProgram\RiProgram.sln" -t:Clean -p:Configuration=ReleaseStatic;Platform=x64
if %errorlevel% neq 0 (
echo Clean Project  "AST(ReleaseStatic)" Fail!
exit 1
)

MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Clean -p:Configuration=Debug;Platform=ARM64
if %errorlevel% neq 0 (
echo Clean Project  "AST(Debug)" Fail!
exit 1
)

MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Clean -p:Configuration=Beta;Platform=ARM64
if %errorlevel% neq 0 (
echo Clean Project  "AST(Beta)" Fail!
exit 1
)

MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Clean -p:Configuration=Stable;Platform=ARM64
if %errorlevel% neq 0 (
echo Clean Project  "AST(Stable)" Fail!
exit 1
)

MSBuild "Q:\Solution File\Real Solution File\RiProgram\RiProgram.sln" -t:Clean -p:Configuration=DebugStatic;Platform=ARM64
if %errorlevel% neq 0 (
echo Clean Project  "AST(DebugStatic)" Fail!
exit 1
)

MSBuild "Q:\Solution File\Real Solution File\RiProgram\RiProgram.sln" -t:Clean -p:Configuration=ReleaseStatic;Platform=ARM64
if %errorlevel% neq 0 (
echo Clean Project  "AST(ReleaseStatic)" Fail!
exit 1
)


MSBuild  "Q:\Solution File\Real Solution File\AST\AST.sln" -t:Build -p:Configuration=%BUILD_TARGET%;Platform=%BUILD_CPU_MODE%
if %errorlevel% neq 0 (
echo  Build Project "AST" Fail!
exit 1
)

MSBuild "Q:\Solution File\Real Solution File\RiProgram\RiProgram.sln" -t:Build -p:Configuration=%BUILD_TARGET_STATIC%;Platform=%BUILD_CPU_MODE%
if %errorlevel% neq 0 (
echo  Build Project "RiProgram" Fail!
exit 1
)

del /s .\build\FinalOut\AST\*.pdb
del /s .\build\FinalOut\RiProgram\*.pdb
del .\build\FinalOut\AST\Mapping.txt

mkdir .\build\WinPE
mkdir .\build\WinPE\MountFloder

copy .\WinPE\boot.wim .\build\WinPE\boot.wim
dism /Mount-Image /ImageFile:.\build\WinPE\boot.wim /Index:1 /MountDir:.\build\WinPE\MountFloder
if %errorlevel% neq 0 (
echo  Mount Image Fail!
exit 1
)

xcopy /E /Y .\build\FinalOut\RiProgram\ ".\build\WinPE\MountFloder\Windows\"
if %errorlevel% neq 0 (
echo  Copy RiProgram Fail!
exit 1
)

copy /A /Y .\WinPE\Winpeshl.ini ".\build\WinPE\MountFloder\Windows\System32\Winpeshl.ini"
if %errorlevel% neq 0 (
echo  Copy WinpeInit Fail!
exit 1
)

dism /Unmount-Image /MountDir:.\build\WinPE\MountFloder /Commit

xcopy /E /Y .\build\FinalOut\AST\ ".\build\FinalProgram\AZPEP SysRi Tool\"
if %errorlevel% neq 0 (
echo  Copy Final File Fail!
exit 1
)

mkdir .\build\AdditionToFinalFile
xcopy /E /Y ".\AdditionToFinalFile\" ".\build\AdditionToFinalFile\"
if %errorlevel% neq 0 (
echo  Copy Addition File Fail!
exit 1
)

copy /B /Y .\build\WinPE\boot.wim ".\build\AdditionToFinalFile\AZPEP SysRi Tool\Data\WinPE\boot.wim"
if %errorlevel% neq 0 (
echo  Copy WinPE File Fail!
exit 1
)

xcopy /E /Y .\build\AdditionToFinalFile\ ".\build\FinalProgram\"
if %errorlevel% neq 0 (
echo  Copy Addition File to Final File Fail!
exit 1
)

Q:\Tools\7z\7z.exe a -tzip "Q:\build\AZPEP SysRi Tool - %BUILD_TARGET%.zip" ".\build\FinalProgram\*"
if %errorlevel% neq 0 (
echo  Make Zip File Fail!
exit 1
)

